package com.example.keymanagers.Dao;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.keymanagers.bean.Bean;
import com.example.keymanagers.db.dbsqlhelper ;

import java.util.ArrayList;
import java.util.List;


public class KeyDao  {

    private final com.example.keymanagers.db.dbsqlhelper dbsqlhelper;

    public KeyDao(Context context) {

        dbsqlhelper = new dbsqlhelper(context);


    }
    public List<Bean> getall(){
     List<Bean> list=new ArrayList<>();
     Bean ba;
        SQLiteDatabase db=dbsqlhelper.getReadableDatabase();
        String sql="select * from keys";
        Cursor cs = db.rawQuery(sql, null);
        while(cs.moveToNext()){
            ba=new Bean();
            ba.set_id(cs.getInt(0));
            ba.setAddress(cs.getString(1));
            ba.setRoom(cs.getString(2));
            ba.setDate(cs.getString(3));

           list.add(ba);


        }



        return  list;
    }
}
